﻿
using System;
using System.Collections.Generic;
 
using System.Web.Mvc;
using System.Web.Security;
using CarTrackr.Business;
using CarTrackr.Business.Services;

namespace CarTrackr.Controllers
{
    [Authorize]
    public class AdminController : Controller
    {
        private IAppService service;

  
        public AdminController(): this(new AppService())
        {           
        }

        public AdminController(IAppService appService)
        {
           service = appService;
        }



        public ActionResult ListUsers()
        {

            var members = Membership.GetAllUsers();

            List<User> users = new List<User>();
            foreach(MembershipUser  member  in members)
            {
                 users.Add(Business.User.GetFromMembershipUser(member));
            }

            return View(users);
        }


      
        public ActionResult  Remove(string userName)
        {
            Membership.DeleteUser(userName);

            return  RedirectToAction("ListUsers", "Admin");
        }


        public string Unlock(string userName)
        {
            Membership.Provider.UnlockUser(userName);

            return userName + " is unlocked.";

             
        }


    }
}
